<template>
  <div>
    <!-- 面包屑导航栏 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>订单管理</el-breadcrumb-item>
    <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <!-- 表格 -->
      <div>
        <!-- 搜索框和添加按钮 -->
        <el-row :gutter="80">
          <el-col :span="8">
            <el-input placeholder="请输入查询内容" v-model="queryInfo.query" clearable>
              <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <el-table :data="orderList" border stripe style="margin-top:15px">
          <el-table-column type="index" label="#"></el-table-column>
          <el-table-column label="订单编号" width="250px" prop="order_number"></el-table-column>
          <el-table-column label="订单价格" width="80px" prop="order_price"></el-table-column>
          <el-table-column label="是否付款" width="100px" prop="order_pay">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.pay_status === '0'" type="danger">未付款</el-tag>
              <el-tag v-if="scope.row.pay_status === '1'" type="success">已付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="是否发货" width="80px" prop="is_send"></el-table-column>
          <el-table-column label="下单时间" prop="create_time">
            <template slot-scope="scope">
              {{ scope.row.create_time | dataFormat}}
            </template>
          </el-table-column>
          <el-table-column prop="operation" label="操作" width="300px">
            <template>
              <el-button type="primary" icon="el-icon-edit" size="mini"
                @click="showEditDialog">修改地址</el-button>
              <el-button type="success" @click="showProgressBox" icon="el-icon-location"
                size="mini">物流进度</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <el-pagination style="margin-top:15px" @size-change="handleSizeChange" @current-change="handleCurrentChange" background
        :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <el-dialog title="修改地址" :visible.sync="eidtDialogVisible" width="50%" @close="closeDialog">
      <el-form ref="editFormRef" :rules="editFormRules" :model="editForm" label-width="80px">
        <el-form-item label="省市区县" prop="address1" >
          <el-cascader :options="cityData" v-model="editForm.address1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2" >
          <el-input v-model="editForm.address2" placeholder="详细地址"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" cel-formlass="dialog-footer">
        <el-button @click="eidtDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="eidtDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="查看物流进度" :visible.sync="progressBoxVisible" width="80%">
      <el-timeline :reverse="reverse">
        <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './city-data.js';
export default {
  created () {
    this.getOrderList()
  },
  data () {
    return {
      editForm: {
        address1: '',
        address2: ''
      },
      cityData,
      editFormRules: {
        address1: [
          { required: true, message: '请输入省市区/县', trigger: 'blur' }
        ],
        address2: [
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      eidtDialogVisible: false,
      progressBoxVisible: false,
      orderList: [],
      total: 0,
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        consignee_addr: ''
      },
      progressInfo: []
    }
  },
  methods: {
    showEditDialog () {
      this.eidtDialogVisible = true
    },
    async showProgressBox () {
      this.progressBoxVisible = true
      const { data: res } = await this.$http.get('/kuaidi/1106975712662', { params: this.queryInfo })
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.progressInfo = res.data
      console.log(this.progressInfo)
    },
    // 监听pagesize改变
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      // 注意改变后要重新获取列表
      this.getOrderList()
    },
    // 监听页码值改变
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getOrderList()
    },
    async getOrderList () {
      const { data: res } = await this.$http.get('/orders', { params: this.queryInfo })
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    closeDialog () {
      this.$refs.editFormRef.resetFields()
    }
  }
}
</script>

<style lang='less' scoped>
.el-cascader  {
  width: 100% !important;
  .el-form-item__label{
    font-size: 13px !important;
  }
}
</style>
